package com.blog.vo;

import com.blog.entity.Comment;
import lombok.Data;

import java.time.LocalDateTime;
import java.util.List;

@Data
public class CommentVO {
    
    private Long id;
    
    private Long articleId;
    
    private Long userId;
    
    private String username;
    
    private String avatar;
    
    private String content;
    
    private Long parentId;
    
    private Long replyToUserId;
    
    private String replyToUsername;
    
    private Integer status;
    
    private LocalDateTime createTime;
    
    private List<CommentVO> children;
    
    public static CommentVO fromComment(Comment comment) {
        CommentVO vo = new CommentVO();
        vo.setId(comment.getId());
        vo.setArticleId(comment.getArticleId());
        vo.setUserId(comment.getUserId());
        vo.setUsername(comment.getUsername());
        vo.setAvatar(comment.getAvatar());
        vo.setContent(comment.getContent());
        vo.setParentId(comment.getParentId());
        vo.setReplyToUserId(comment.getReplyToUserId());
        vo.setReplyToUsername(comment.getReplyToUsername());
        vo.setStatus(comment.getStatus());
        vo.setCreateTime(comment.getCreateTime());
        
        if (comment.getChildren() != null && !comment.getChildren().isEmpty()) {
            vo.setChildren(comment.getChildren().stream()
                    .map(CommentVO::fromComment)
                    .toList());
        }
        
        return vo;
    }
} 